package com.atguigu.lease.web.app.service.impl;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.atguigu.lease.web.app.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsServiceImpl implements SmsService {

    @Autowired
    private Client client ;

    @Override
    public void sendCode(String phone, String verifyCode) throws Exception {
        SendSmsRequest request = new SendSmsRequest();

        request.setSignName("阿里云短信测试");
        request.setTemplateCode("SMS_154950909");
        request.setPhoneNumbers(phone);
        request.setTemplateParam("{\"code\":\"" + verifyCode + "\"}\n");  // 模板参数 ， 如果写错了不抛出任何异常，需要注意
        client.sendSms(request);
    }
}
